﻿
namespace FastCode
{

    public class ColumnConfig
    {
        public string Name { get; set; }
        public int Order { get; set; }
        public string Label { get; set; }
        public EUIType ControlType { get; set; }
        public string TypeName { get; set; }
        public bool IsShow { get; set; }
        public bool IsEditable { get; internal set; }
        /// <summary>
        /// 是否可为空
        /// </summary>
        public bool IsNullable { get; set; }
        /// <summary>
        /// 如果该字段是枚举类型，存为字典
        /// </summary>
        public Dictionary<int, string> EnumDic { get; set; }
    }

    /// <summary>
    /// 前端根据字段标记的类型，渲染对应控件
    /// </summary>
    [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
    public class UITypeAttribute : Attribute
    {
        //public EUIType ControlType { get; set; } = EUIType.Text;

        public ColumnConfig ColumnConfig { get; set; }
        //public string Label { get; set; }

        ///// <summary>
        ///// 排序，数越小越靠前
        ///// </summary>
        //public int Order { get; set; }

        ///// <summary>
        ///// 是否列表显示
        ///// </summary>
        //public bool IsShow { get; set; }
        ///// <summary>
        ///// 是否可编辑的
        ///// </summary>
        //public bool IsEditable { get; set; }

        public UITypeAttribute(EUIType type = EUIType.Text, string label = "", int order = 100, bool isShow = true, bool isEditable = true)
        {
            ColumnConfig = new ColumnConfig
            {
                ControlType = type,
                Label = label,
                Order = order,
                IsShow = isShow,
                IsEditable = isEditable
            };
            //ControlType = type;
            //Label = label;
            //Order = order;
            //IsShow = isShow;
            //IsEditable = isEditable;
        }
    }

    public enum EUIType : byte
    {
        Code = 1,
        Num = 2,
        Text = 3,
        Phone = 4,
        Date = 5,
        Option = 6,
        Enum = 7,
    }
}
